package com.javaee.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.javaee.entity.User;
import com.javaee.service.UserService;

@Controller
public class IndexController {

	@Autowired
	UserService userService;
	
	@RequestMapping("/index")
	public String goWebSocketView(){
		
		return "index";
	}
	
	
	@RequestMapping("/updateUser")
	@ResponseBody
	@Transactional
	public String updateUser(){
		try {
			User user = new User();
			user.setId(6);
			user.setAge(25);
			user.setName("杨善林");
			user.setPassword("123456");
			user.setUsername("yangshanlin");
			userService.addUser(user);
			
			user.setId(5);
			user.setAge(20);
			user.setName("小鸡鸡");
			user.setPassword("123456");
			user.setUsername("jiji");
			userService.addUser(user);
			
		} catch (Exception e) {
			String result = "出现异常，事务回滚!";
			throw new RuntimeException(result);
		}
		return "success";
	}
	
}
